import 'dart:convert';
import 'dart:io';

import 'package:amway_superapp_creator_plugin/analysis/zhuge_circle.dart';
import 'package:amway_superapp_creator_plugin/config/colors_config.dart';
import 'package:amway_superapp_creator_plugin/dialog/comm_tip_dialog.dart';
import 'package:amway_superapp_creator_plugin/dialog/common_bottom_sheet.dart';
import 'package:amway_superapp_creator_plugin/dialog/loading_dialog.dart';
import 'package:amway_superapp_creator_plugin/models/circle_detail_model.dart';
import 'package:amway_superapp_creator_plugin/models/create_user_info_model.dart';
import 'package:amway_superapp_creator_plugin/models/my_circle_bean.dart';
import 'package:amway_superapp_creator_plugin/routers/application.dart';
import 'package:amway_superapp_creator_plugin/routers/routes.dart';
import 'package:amway_superapp_creator_plugin/utils/image_pickasset_util.dart';
import 'package:amway_superapp_creator_plugin/utils/sp_util.dart';
import 'package:amway_superapp_creator_plugin/utils/toast_util.dart';
import 'package:amway_superapp_creator_plugin/viewmodels/circle/my_circle_model.dart';
import 'package:amway_superapp_creator_plugin/views/base_view.dart';
import 'package:amway_superapp_creator_plugin/views/circle/event.dart';
import 'package:amway_superapp_creator_plugin/widget/slide_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:provider/provider.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

import '../image_bean.dart';

class MyCircle extends StatefulWidget {
  String amwayAda;
  String amwayId;
  var identityMarks;

  MyCircle(
      {@required this.amwayAda, @required this.amwayId, this.identityMarks});

  int page = 1;

  @override
  _MyCircleState createState() => _MyCircleState();
}

class _MyCircleState extends State<MyCircle> {
  EasyRefreshController _controller = new EasyRefreshController();
  MyCircleModel circleModel;
  bool officialCircleCheck = false;

  @override
  Widget build(BuildContext context) {
    eventBus.on<CircleBackEvent>().listen((event) {
      if (event.event && circleModel != null) {
        circleModel.getCircleList(
            widget.amwayAda, widget.amwayId, widget.identityMarks,
            page: 1, isChecked: circleModel.isChecked);
      }
    });
    return BaseView(
        model: MyCircleModel(api: Provider.of(context)),
        onModelReady: (model) async {
          circleModel = model;
          SpUtil.getData("${SpUtil.official_circle}${widget.amwayAda}")
              .then((value) {
            if (value == null) {
              officialCircleCheck = false;
            } else {
              if (value == "ON") {
                officialCircleCheck = true;
              } else {
                officialCircleCheck = false;
              }
            }
            model.checked(officialCircleCheck);

            model.getCircleList(
                widget.amwayAda, widget.amwayId, widget.identityMarks,
                page: 1, isChecked: officialCircleCheck);
            ZhugeCircleAnalysis.circlePagLoadFinsh();
          });
        },
        builder: ((context, model, child) => Scaffold(
              appBar: AppBar(
                elevation: 0,
                brightness: Brightness.light,
                backgroundColor: Colors.white,
                leading: IconButton(
                  icon: Image.asset(
                    'picture/icon_back.png',
                    package: 'amway_superapp_creator_plugin',
                  ),
                  onPressed: () {
                    Application.router.pop(context);
                  },
                ),
                centerTitle: true,
                title: Text(
                  "我的圈子",
                  style: TextStyle(
                      color: ColorsConfig.c_2c2c2c,
                      fontSize: ScreenUtil().setSp(18)),
                ),
              ),
              body: GestureDetector(
                  onTap: () {
                    if (slideKey != null) {
                      slideKey.currentState.close();
                    }
                  },
                  child: Column(
                    children: [
                      Container(
                          padding:
                              EdgeInsets.symmetric(vertical: 8, horizontal: 10),
                          decoration: BoxDecoration(
                            color: ColorsConfig.c_33fafafa,
                            border: Border.all(
                                width: 0.5, color: ColorsConfig.c_e6e6e6),
                            borderRadius: BorderRadius.circular(
                                ScreenUtil().setWidth(12)),
                          ),
                          margin: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(12),
                              ScreenUtil().setWidth(12),
                              ScreenUtil().setWidth(12),
                              0),
                          child: Row(
//            mainAxisSize: MainAxisSize.min,
                            children: [
                              InkWell(
                                onTap: () {
                                  setState(() {
                                    model.setChecked(
                                        model.isChecked ? false : true);
                                    model.upModuleOffShow(widget.amwayAda);
                                    ZhugeCircleAnalysis.circlePageCheck("我的圈子",
                                        isSel: model.isChecked ? false : true);
                                  });
                                },
                                child: Container(
                                  padding:
                                      EdgeInsets.all(ScreenUtil().setWidth(5)),
                                  child: model.isChecked
                                      ? Image.asset(
                                          'picture/icon_circle_checked.png',
                                          width: ScreenUtil().setWidth(22),
                                          height: ScreenUtil().setWidth(22),
                                          package:
                                              'amway_superapp_creator_plugin')
                                      : Image.asset(
                                          'picture/icon_circle_un_checked.png',
                                          width: ScreenUtil().setWidth(22),
                                          height: ScreenUtil().setWidth(22),
                                          package:
                                              'amway_superapp_creator_plugin'),
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(
                                    left: ScreenUtil().setWidth(5)),
                                child: Text(
                                  "在我的圈子中展示官方文章/视频",
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: ScreenUtil().setSp(16)),
                                ),
                              )
                            ],
                          )),
                      Expanded(
                          flex: 1,
                          child: Container(
                              color: Colors.white,
                              child: EasyRefresh(
                                  controller: _controller,
                                  header: ClassicalHeader(
                                      refreshingText: "刷新中",
                                      refreshReadyText: "可以刷新",
                                      refreshText: "刷新",
                                      refreshedText: "刷新完成",
                                      showInfo: false),
                                  footer: ClassicalFooter(
                                      loadedText: "正在加载中...",
                                      loadFailedText: "加载失败",
                                      noMoreText: "没有更多了",
                                      bgColor: Colors.white,
                                      showInfo: false,
                                      textColor: Colors.black),
                                  // onLoad: () async {
                                  //   if (model.myCircleData.totalElements >
                                  //       model.myCircleData
                                  //           .numberOfElements) {
                                  //     model.getCircleList(
                                  //       widget.amwayAda,
                                  //       page: widget.page++,
                                  //     );
                                  //     // _controller.resetLoadState();
                                  //   }
                                  // },
                                  onRefresh: () async {
                                    widget.page = 1;
                                    model.getCircleList(widget.amwayAda,
                                        widget.amwayId, widget.identityMarks,
                                        page: widget.page,
                                        isChecked: model.isChecked);
                                  },
                                  child: model.filterOfficial().length == 0
                                      ? Container(
                                          alignment: Alignment.center,
                                          margin: EdgeInsets.only(
                                              top: ScreenUtil().setHeight(280)),
                                          child: Text("暂无数据"),
                                        )
                                      : model.isChecked == true
                                          ? model.filterOfficial().length == 0
                                              ? Container(
                                                  alignment: Alignment.center,
                                                  margin: EdgeInsets.only(
                                                      top: ScreenUtil()
                                                          .setHeight(280)),
                                                  child: Text("暂无数据"),
                                                )
                                              : ListView(
                                                  children: getSlides(
                                                      model.filterOfficial(),
                                                      model))
                                          : model.officialList.length == 0
                                              ? Container(
                                                  alignment: Alignment.center,
                                                  margin: EdgeInsets.only(
                                                      top: ScreenUtil()
                                                          .setHeight(280)),
                                                  child: Text("暂无数据"),
                                                )
                                              : ListView(
                                                  children: getSlides(
                                                      model.officialList,
                                                      model),
                                                ))))
                    ],
                  )),
              bottomNavigationBar: _add(model),
            )));
  }

  GlobalKey<SlideButtonState> slideKey;

  List<SlideButton> getSlides(List<MyCircleBean> circle, MyCircleModel model) {
    if (circle == null) return [];
    final list = List<SlideButton>();
    for (var i = 0; i < circle.length; i++) {
      var key = GlobalKey<SlideButtonState>();
      var slide = SlideButton(
        key: key,
        singleButtonWidth: circle[i].officialFlag == "YES" //官方的
            ? 0
            : circle[i].auditStatus == "NONE" ||
                    circle[i].auditStatus == "AUDITING"
                ? 0
                : circle[i].officialFlag == "NO" &&
                        circle[i].auditStatus == "AUDITING"
                    ? ScreenUtil().setWidth(90) //自定义且未待审核状态
                    : circle[i].officialFlag == "NO" &&
                            circle[i].auditStatus == "NONE"
                        ? ScreenUtil().setWidth(90)
                        : circle[i].officialFlag == "NO" && //已发布 删除
                                circle[i].publishStatus == "PUBLISHED"
                            ? ScreenUtil().setWidth(180)
                            : ScreenUtil().setWidth(90),
        onSlideStarted: () {
          for (var i = 0; i < list.length; i++) {
            if (list[i].key != key) {
              list[i].key.currentState?.close();
            } else {
              slideKey = list[i].key;
              var sendState = 2;
              if (circle[i].publishStatus == "PUBLISHED") {
                sendState = 0;
              } else if (circle[i].auditStatus == "UN_PASS") {
                sendState = 1;
              } else {
                sendState = 2;
              }
              ZhugeCircleAnalysis.circleLeftDrawCard(
                  "我的圈子", sendState, circle[i].id, circle[i].title);
            }
          }
        },
        child: Container(
          height: ScreenUtil().setWidth(130),
          child: _item(i, circle, model, key),
          width: double.infinity,
        ),
        buttons: <Widget>[
          circle[i].officialFlag == "NO"
              ? buildAction(circle, i, key, () {
                  key.currentState.close();
                }, model)
              : Container(),
        ],
      );
      list.add(slide);
    }
    return list;
  }

  InkWell buildAction(
      List<MyCircleBean> circle,
      int index,
      GlobalKey<SlideButtonState> key,
      GestureTapCallback tap,
      MyCircleModel model) {
    var sendState = 2;
    if (circle[index].publishStatus == "PUBLISHED") {
      sendState = 0;
    } else if (circle[index].auditStatus == "UN_PASS") {
      sendState = 1;
    } else {
      sendState = 2;
    }
    return InkWell(
      onTap: tap,
      child: Container(
          padding: circle[index].publishStatus == "PUBLISHED" && //自定义已发布 撤销删除
                  circle[index].officialFlag == "NO"
              ? EdgeInsets.only(left: ScreenUtil().setWidth(20))
              : EdgeInsets.only(left: ScreenUtil().setWidth(0)),
          margin: EdgeInsets.fromLTRB(
              0,
              index == 0 ? ScreenUtil().setWidth(13) : ScreenUtil().setWidth(7),
              ScreenUtil().setWidth(13),
              index == circle.length - 1
                  ? ScreenUtil().setWidth(13)
                  : ScreenUtil().setWidth(7)),
          alignment: Alignment.center,
          width: circle[index].publishStatus == "PUBLISHED" && //自定义已发布 撤销删除
                  circle[index].officialFlag == "NO"
              ? ScreenUtil().setWidth(210)
              : ScreenUtil().setWidth(100),
          height: ScreenUtil().setWidth(130),
          child: circle[index].publishStatus == "PUBLISHED" && //自定义已发布 撤销删除
                  circle[index].officialFlag == "NO"
              ? Row(children: [
                  Container(
                    width: ScreenUtil().setWidth(100),
                    color: ColorsConfig.c_de7d1b,
                    padding: EdgeInsets.only(left: ScreenUtil().setWidth(5)),
                    alignment: Alignment.center,
                    child: InkWell(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset("picture/icon_revoke.png",
                              width: ScreenUtil().setSp(24),
                              height: ScreenUtil().setSp(24),
                              package: 'amway_superapp_creator_plugin'),
                          Text(
                            "撤销发布",
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: ScreenUtil().setSp(12)),
                          )
                        ],
                      ),
                      onTap: () {
                        key.currentState.close();
                        showDialog(
                            context: context,
                            barrierDismissible: false,
                            builder: (_) {
                              return CommTipDialog(
                                content: '确认撤销发布此圈子动态吗？',
                                confirmText: "确认",
                                confirmCallback: () {
                                  showDialog(
                                    context: context,
                                    builder: (ctx) {
                                      return LoadingDialog(
                                        canceledOnTouchOutside: false,
                                        tipMsg: '正在撤销',
                                      );
                                    },
                                  );
                                  model.revoke(circle[index].id, index,
                                      back: (value, msg) {
                                    Application.router.pop(context);
                                    if (value) {
                                      ToastUtils.showShortToast("撤销成功");
                                    } else {
                                      ToastUtils.showShortToast(msg);
                                    }
                                  });
                                },
                                dismissCallback: () {},
                              );
                            });
                      },
                    ),
                  ),
                  InkWell(
                    child: Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topRight:
                                  Radius.circular(ScreenUtil().setWidth(12)),
                              bottomRight:
                                  Radius.circular(ScreenUtil().setWidth(12))),
                          color: ColorsConfig.c_c53434),
                      width: ScreenUtil().setWidth(90),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.delete_forever,
                            size: ScreenUtil().setSp(24),
                            color: Colors.white,
                          ),
                          Text(
                            "删除",
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: ScreenUtil().setSp(12)),
                          )
                        ],
                      ),
                    ),
                    onTap: () {
                      key.currentState.close();
                      showDialog(
                          context: context,
                          barrierDismissible: false,
                          builder: (_) {
                            return CommTipDialog(
                              content: '确认删除此圈子动态吗？',
                              confirmText: "确认",
                              confirmCallback: () {
                                ZhugeCircleAnalysis.circleDelCard(
                                    "我的圈子",
                                    sendState,
                                    circle[index].id,
                                    circle[index].title);
                                showDialog(
                                  context: context,
                                  builder: (ctx) {
                                    return LoadingDialog(
                                      canceledOnTouchOutside: false,
                                      tipMsg: '正在删除',
                                    );
                                  },
                                );
                                model.deleteCircle(circle[index].id, index,
                                    back: (value, msg) {
                                  Application.router.pop(context);
                                  if (value) {
                                    ToastUtils.showShortToast("删除成功");
                                    model.setChecked(model.isChecked);
                                  } else {
                                    ToastUtils.showShortToast(msg);
                                  }
                                });
                              },
                              dismissCallback: () {},
                            );
                          });
                    },
                  )
                ])
              : InkWell(
                  child: Container(
                      width: ScreenUtil().setWidth(90),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topRight:
                                  Radius.circular(ScreenUtil().setWidth(12)),
                              bottomRight:
                                  Radius.circular(ScreenUtil().setWidth(12))),
                          color: ColorsConfig.c_c53434),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.delete_forever,
                            size: ScreenUtil().setSp(24),
                            color: Colors.white,
                          ),
                          Text(
                            "删除",
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: ScreenUtil().setSp(12)),
                          )
                        ],
                      )),
                  onTap: () {
                    key.currentState.close();
                    showDialog(
                        context: context,
                        barrierDismissible: false,
                        builder: (_) {
                          return CommTipDialog(
                            content: '确认删除此圈子动态吗？',
                            confirmText: "确认",
                            confirmCallback: () {
                              showDialog(
                                context: context,
                                builder: (ctx) {
                                  return LoadingDialog(
                                    canceledOnTouchOutside: false,
                                    tipMsg: '正在删除',
                                  );
                                },
                              );
                              model.deleteCircle(circle[index].id, index,
                                  back: (value, msg) {
                                Application.router.pop(context);
                                if (value) {
                                  ToastUtils.showShortToast("删除成功");
                                  model.setChecked(model.isChecked);
                                } else {
                                  ToastUtils.showShortToast(msg);
                                }
                              });
                            },
                            dismissCallback: () {},
                          );
                        });
                  },
                )),
    );
  }

  Widget _item(int index, List<MyCircleBean> circle, MyCircleModel model,
      GlobalKey<SlideButtonState> key) {
    return GestureDetector(
        onTap: () {
          key.currentState.close();

          if (circle[index].officialFlag == "YES") {
            Map<String, dynamic> parameters = {};
            parameters['time'] = circle[index].publishDate;
            parameters['officialId'] = circle[index].officialId;
            parameters['title'] = circle[index].title;
            parameters['images'] = circle[index].medias;
            Application.router.navigateTo(context, Routes.OFFICIALDETAIL,

                routeSettings: RouteSettings(arguments: parameters));
          } else {
            Map<String, dynamic> parameters = {
              'id': circle[index].id,
            };
            if (circle[index].publishStatus == "UN_PUBLISH") {
              if (circle[index].auditStatus == "NONE" ||
                  circle[index].auditStatus == "AUDITING") {
                return;
              }
            }
            if (circle[index].medias[0].dataType == "VIDEO") {
              Application.router.navigateTo(
                  context, Routes.MYCIRCLEDETAILSVIDEO,
                  routeSettings: RouteSettings(arguments: parameters));
            } else {
              Application.router
                  .navigateTo(context, Routes.MYCIRCLEDETAILSIMAGES,
                      routeSettings: RouteSettings(arguments: parameters))
                  .then((value) {
                model.getCircleList(
                    widget.amwayAda, widget.amwayId, widget.identityMarks,
                    page: 1, isChecked: model.isChecked);
              });
            }
          }
        },
        child: Stack(
          children: [
            _circle(index, circle),
            circle[index].officialFlag == "YES"
                ? Positioned(
                    child: _recommend(),
                    left: ScreenUtil().setWidth(35),
                    top: ScreenUtil().setHeight(3),
                  )
                : Container(),
            Positioned(
                right: 14,
                bottom: index == circle.length - 1
                    ? ScreenUtil().setWidth(11)
                    : ScreenUtil().setWidth(6),
                child: circle[index].publishStatus == "PUBLISHED" //已发布
                    ? Image.asset(
                        "picture/icon_published.png",
                        width: ScreenUtil().setWidth(80),
                        height: ScreenUtil().setWidth(80),
                        package: 'amway_superapp_creator_plugin',
                      )
                    : circle[index].auditStatus == "UN_PASS" //审核不通过
                        ? Image.asset(
                            "picture/icon_audit_no_pass.png",
                            width: ScreenUtil().setWidth(80),
                            height: ScreenUtil().setWidth(80),
                            package: 'amway_superapp_creator_plugin',
                          )
                        : circle[index].auditStatus == "PASSED" &&
                                circle[index].publishStatus ==
                                    "UN_PUBLISH" //待发布
                            ? Image.asset(
                                "picture/icon_to_be_released.png",
                                width: ScreenUtil().setWidth(80),
                                height: ScreenUtil().setWidth(80),
                                package: 'amway_superapp_creator_plugin',
                              )
                            : circle[index].auditStatus == "NONE" ||
                                    circle[index].auditStatus ==
                                        "AUDITING" //审核中
                                ? Image.asset(
                                    "picture/icon_review.png",
                                    width: ScreenUtil().setWidth(80),
                                    height: ScreenUtil().setWidth(80),
                                    package: 'amway_superapp_creator_plugin',
                                  )
                                : Container())
          ],
        ));
  }

  Widget _circle(int index, List<MyCircleBean> circle) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(12),
          boxShadow: [
            BoxShadow(
                color: ColorsConfig.c_1a000000,
                offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                blurRadius: 20.0, //阴影模糊程度
                spreadRadius: 0.0 //阴影扩散程度
                )
          ]),
      margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(12),
          index == 0 ? ScreenUtil().setWidth(12) : ScreenUtil().setWidth(6),
          ScreenUtil().setWidth(12),
          index == circle.length - 1
              ? ScreenUtil().setWidth(12)
              : ScreenUtil().setWidth(6)),
      child: Row(
        children: [_image(circle[index]), _rItem(circle[index])],
      ),
    );
  }

/*
* 图片
* */
  Widget _image(MyCircleBean bean) {
    return Stack(children: [
      Container(
          margin: EdgeInsets.only(left: ScreenUtil().setWidth(12)),
          alignment: Alignment.centerLeft,
          child: Image.network(
            bean.medias[0] != null && bean.medias[0].data != null
                ? bean.medias[0].data
                : "https://pic2.zhimg.com/v2-639b49f2f6578eabddc458b84eb3c6a1.jpg",
            width: ScreenUtil().setWidth(70),
            height: ScreenUtil().setWidth(90),
            fit: BoxFit.cover,
          )),
      bean.medias != null &&
              bean.medias[0].dataType != null &&
              bean.medias[0].dataType == "VIDEO"
          ? Positioned(
              top: ScreenUtil().setWidth(40),
              left: ScreenUtil().setWidth(35),
              child: Icon(
                Icons.play_circle_fill,
                color: Colors.white,
                size: ScreenUtil().setWidth(30),
              ))
          : Container()
    ]);
  }

  Widget _rItem(MyCircleBean bean) {
    bool toBeReleased = bean.auditStatus == "PASSED" &&
        bean.publishStatus == "UN_PUBLISH"; //待发布
    return Expanded(
        child: Column(
      children: [
        _title(bean.title),
        _bottomItem(bean.medias[0], bean.auditStatus, toBeReleased)
      ],
    ));
  }

  /*
  * 标题
  * */
  Widget _title(String title) {
    return Expanded(
        child: Container(
      alignment: Alignment.topLeft,
      margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(5), ScreenUtil().setWidth(5), 0),
      child: Text(title != null ? title : "暂无标题",
          maxLines: 2,
          overflow: TextOverflow.ellipsis,
          style:
              TextStyle(color: Colors.black, fontSize: ScreenUtil().setSp(18))),
    ));
  }

  Widget _bottomItem(ImagesBean media, String auditStatus, bool toBeReleased) {
    return Container(
      margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(10), 0, 0, ScreenUtil().setWidth(10)),
      child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
        Icon(
          Icons.image,
          size: ScreenUtil().setWidth(15),
          color: Colors.black45,
        ),
        Container(
          margin: EdgeInsets.only(left: ScreenUtil().setWidth(3)),
          child: Text(
              media != null &&
                      media.dataType != null &&
                      media.dataType == "VIDEO"
                  ? "视频"
                  : "图文",
              style: TextStyle(
                  color: ColorsConfig.c_802c2c2c,
                  fontSize: ScreenUtil().setSp(12))),
        ),
        // auditStatus == "NONE" ||
        //         auditStatus == "AUDITING" ||
        //         auditStatus == "UN_PASS" ||
        //         toBeReleased
        //     ? Container()
        //     : Row(
        //         children: [
        //           Container(
        //             margin: EdgeInsets.only(left: ScreenUtil().setWidth(15)),
        //             child: Icon(Icons.remove_red_eye_rounded,
        //                 size: ScreenUtil().setWidth(18), color: Colors.black45),
        //           ),
        //           Container(
        //             margin: EdgeInsets.only(left: ScreenUtil().setWidth(3)),
        //             child: Text("2517",
        //                 style: TextStyle(
        //                     color: ColorsConfig.c_802c2c2c,
        //                     fontSize: ScreenUtil().setSp(12))),
        //           )
        //         ],
        //       )
      ]),
    );
  }

  Widget _recommend() {
    return Stack(alignment: Alignment.center, children: [
      Image.asset(
        "picture/icon_official_recommend.png",
        package: 'amway_superapp_creator_plugin',
      ),
      Container(
          margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(5)),
          child: new Text(
            '官方推荐',
            style: new TextStyle(
              fontSize: ScreenUtil().setSp(10),
              color: Colors.white,
            ),
          ))
    ]);
  }

  Widget _add(MyCircleModel model) {
    return Container(
        decoration: BoxDecoration(color: Colors.white, boxShadow: [
          BoxShadow(
              color: ColorsConfig.c_26000000,
              offset: Offset(0.0, 2.0), //阴影xy轴偏移量
              blurRadius: 15.0, //阴影模糊程度
              spreadRadius: 0.0 //阴影扩散程度
              )
        ]),
        padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(34)),
        child: Container(
            width: double.infinity,
            height: ScreenUtil().setWidth(50),
            child: InkWell(
              onTap: () {
                if (slideKey != null) {
                  slideKey.currentState?.close();
                }
                ZhugeCircleAnalysis.circleAddVideoAlbumPage("我的圈子");
                Map<String, dynamic> parameters;
                SpUtil.getData("${SpUtil.user_circle}${widget.amwayAda}")
                    .then((value) {
                  if (value == null) {
                    //没有草稿
                    parameters = {
                      'isNewAdd': true,
                      'circleData': null,
                      'amwayId': widget.amwayId,
                      'amwayAda': widget.amwayAda,
                      'isUserDraft': false
                    };

                    pickAssetCamera(context, RequestType.image,
                            maxAssetsCount: 9)
                        .then((value) {
                      List<Future<File>> uploadQueue = new List();
                      List<ImageBean> mImages = [];
                      for (AssetEntity assetEntity in value) {
                        uploadQueue.add(assetEntity.file);
                      }
                      Future.wait(uploadQueue).then((results) {
                        // print(results[0].toString()+results[1]);
                        for (int i = 0; i < results.length; i++) {
                          mImages.add(ImageBean(file: results[i]));
                        }
                      }).catchError((e) {
                        print(e);
                      }).whenComplete(() {
                        parameters['images'] = mImages;
                        Application.router
                            .navigateTo(context, Routes.SENDCIRCLE,
                                routeSettings:
                                    RouteSettings(arguments: parameters))
                            .then((value) {
                          if (value != null) {
                            model.getCircleList(widget.amwayAda, widget.amwayId,
                                widget.identityMarks,
                                page: 1, isChecked: model.isChecked);
                          }
                        });
                      }).asStream();
                    });
                  } else {
                    showDialog(
                        barrierDismissible: true,
                        //是否点击空白区域关闭对话框,默认为true，可以关闭
                        context: context,
                        builder: (BuildContext context) {
                          List<ItemMode> list = List<ItemMode>();
                          list.add(ItemMode(
                              label: '您有一份未完成草稿，要继续编辑吗？',
                              color: ColorsConfig.c_8f8f8f,
                              size: 15));
                          list.add(ItemMode(
                              label: '丢弃草稿',
                              color: ColorsConfig.c_396E75,
                              size: 17));
                          list.add(ItemMode(
                              label: '使用草稿',
                              color: ColorsConfig.c_396E75,
                              size: 17));
                          return CommonBottomSheet(
                            list: list,
                            onItemClickListener: (index) async {
                              Navigator.pop(context);
                              switch (index) {
                                case 2:
                                  SpUtil.clearData(
                                      "${SpUtil.user_circle}${widget.amwayAda}");
                                  parameters = {
                                    'isNewAdd': true,
                                    'circleData': null,
                                    'amwayId': widget.amwayId,
                                    'amwayAda': widget.amwayAda,
                                    'isUserDraft': false
                                  };
                                  break;
                                case 4:
                                  Map<String, dynamic> response =
                                      json.decode(value);
                                  CircleDetailData circleDta =
                                      CircleDetailData.fromJson(response);
                                  parameters = {
                                    'isNewAdd': true,
                                    'circleData': circleDta,
                                    'amwayId': widget.amwayId,
                                    'amwayAda': widget.amwayAda,
                                    'isUserDraft': true
                                  };
                                  break;
                              }
                              Application.router
                                  .navigateTo(context, Routes.SENDCIRCLE,
                                      routeSettings:
                                          RouteSettings(arguments: parameters))
                                  .then((value) {
                                if (value != null) {
                                  model.getCircleList(widget.amwayAda,
                                      widget.amwayId, widget.identityMarks,
                                      page: 1, isChecked: model.isChecked);
                                }
                              });
                            },
                          );
                        });
                  }
                });
              },
              child: Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(25),
                    color: Color(0xff396E75)),
                child: Text(
                  "添加图文/视频",
                  style: TextStyle(
                      color: Colors.white, fontSize: ScreenUtil().setSp(18)),
                ),
              ),
            )));
  }
}
